﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    public class CargoTypeIProvider : IProvider<CargoType>
    {      
        private SMEntities db=new SMEntities();
        public int Delete(int Id)
        {
           
           CargoType entity=  db.CargoType.Find(Id);
            if(entity != null)
            {
                db.CargoType.Remove(entity);
               int  A=   db.SaveChanges();
                return A;
            }
            return 0;
          
        }
        public List<CargoType> GetByKeyWord(string keyword)
        {
            return db.CargoType.Where(d=>d.Name.Contains(keyword)).ToList();
        }

        public List<CargoType> GetAll()
        {
            return db.CargoType.ToList();
        }

        public int Insert(CargoType t)
        {
               db.CargoType.Add(t);
            int A= db.SaveChanges();
            return A;
        }

        public int Update(CargoType t)
        {
             CargoType entity=  db.CargoType.FirstOrDefault(e=>e.Id==t.Id);
             if (entity != null)
        {
            // 修改实体属性值
            entity.Name = t.Name;
            entity.Tag = t.Tag;
                // 保存更改
      return          db.SaveChanges();

        }
           
                return 0;
         
            
        }
        public CargoType GetById(int Id)
        {
            CargoType entity=  db.CargoType.Find(Id);
            return entity;
        }
    }
}
